import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // a modern alternative to CSS resets

import Element from 'element-ui'
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/ruoyi.scss' // ruoyi css
import App from './App'
import store from './store'
import router from './router'
import rolePermiDirective from './directive/permission'
import { checkRole, checkPermi } from './utils/permission'

import './assets/icons' // icon
import './permission' // permission control
import website from '@/utils/website'
import { parseTime, resetForm, addDateRange, selectDictLabel, handleTree } from '@/utils/ruoyi'
import Pagination from '@/components/Pagination'

// 后台请求方法挂载(editable)
import { upload, download } from '@/api/system/common/file'
import { getDicts } from '@/api/system/dict/data'
import { getConfigKey } from '@/api/system/config'
Vue.prototype.$dy_upload = upload
Vue.prototype.$dy_download = download
Vue.prototype.$dy_getDicts = getDicts
Vue.prototype.$dy_getConfigKey = getConfigKey

// 全局方法挂载，可全局替换
Vue.prototype.$dy_website = website
Vue.prototype.$dy_parseTime = parseTime
Vue.prototype.$dy_resetForm = resetForm
Vue.prototype.$dy_addDateRange = addDateRange
Vue.prototype.$dy_selectDictLabel = selectDictLabel
Vue.prototype.$dy_handleTree = handleTree
Vue.prototype.$dy_checkRole = checkRole
Vue.prototype.$dy_checkPermi = checkPermi

Vue.prototype.$dy_msgSuccess = function(msg) {
  this.$message({ showClose: true, message: msg, type: 'success' })
}

Vue.prototype.$dy_msgError = function(msg) {
  this.$message({ showClose: true, message: msg, type: 'error' })
}

Vue.prototype.$dy_msgInfo = function(msg) {
  this.$message.info(msg)
}

// 全局组件挂载
Vue.component('Pagination', Pagination)

Vue.use(rolePermiDirective)

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
